package iwba.simple.controller;
 
import java.security.Principal;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.preludeb.auth.core.PreludebUser;
 
@Controller
public class LoginController {
 
	@RequestMapping(value="/dictionary", method = RequestMethod.GET)
	public String printWelcome(ModelMap model, Principal principal ) {
 
		String name = principal.getName();
		model.addAttribute("username", name);
		model.addAttribute("message", "Spring Security Custom Form example");
		return "/WEB-INF/jsp/dic/dictionary";
 
	}
	
	/*public PreludebUser getUser()
    {
        return (PreludebUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }
    
    @RequestMapping(value = "/dictionary", method = RequestMethod.GET)
    public ModelAndView index()
    {
        ModelAndView view = new ModelAndView();
        view.setViewName("/html/dic/dictionary");
        view.addObject("username", getUser().getUsername());
        
        return view;
    }*/
 
	@RequestMapping(value="/index", method = RequestMethod.GET)
	public String login(ModelMap model) {
 
		return "index";
 
	}
 
	@RequestMapping(value="/loginfailed", method = RequestMethod.GET)
	public String loginerror(ModelMap model) {
 
		model.addAttribute("error", "true");
		return "index";
 
	}
 
	@RequestMapping(value="/logout", method = RequestMethod.GET)
	public String logout(ModelMap model) {
 
		return "index";
 
	}

	
	
/*	@RequestMapping(value="/error", method = RequestMethod.GET)
	public String error(ModelMap model) {
 
		return "/html/dic/dictionary";
 
	}*/
 
}